package com.test.controller;

import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName SysController
 * @Description TODO
 * @Author 逝风无言
 * @Data 2019/9/14 10:59
 * @Version 1.0
 **/
@RestController
public class SysController {




    @RequestMapping("getUser")
    @ResponseBody
    public List<String> getUser(){
        List<String> list = new ArrayList();
        list.add("中北大学");
        list.add("666");
        list.add("实验室");
        return list;
    }

    @RequestMapping(value="getTest",method = RequestMethod.POST)
    @ResponseBody
    public List<String> getTest(@RequestBody JSONObject data){

        System.out.println(data);

        List<String> list = new ArrayList();
        list.add("中北大学");
        list.add("653");
        list.add("实验室");
        return list;
    }

    /**
     * 创建日期:2018年4月6日<br/>
     * 代码创建:黄聪<br/>
     * 功能描述:通过request来获取到json数据<br/>
     * @param request
     * @return
     */
    public JSONObject getJSONParam(HttpServletRequest request){
        JSONObject jsonParam = null;
        try {
            // 获取输入流
            BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));

            // 写入数据到Stringbuilder
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = streamReader.readLine()) != null) {
                sb.append(line);
            }
            jsonParam = JSONObject.parseObject(sb.toString());
            // 直接将json信息打印出来
            System.out.println(jsonParam.toJSONString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return jsonParam;
    }

    /**
     * 新增保存来和申报
     */
    @RequestMapping("add1")
    @ResponseBody
    public int add1()//(TApply tApply)
    {
        int affectCount =  0;//tApplyService.insertTApply(tApply);
        return affectCount;
    }
}
